<template>
  <div class="all">
    <div class="header">
      <van-icon
        class="back"
        @click="goback"
        color="#fff"
        size="25px"
        name="arrow-left"
      />
    </div>
    <div class="space"></div>
    <div class="middlebox">
      <div class="intpart">
        <van-icon class="search" color="#333" size="24" name="search" />
        <input type="text" v-model="address" placeholder="输入您的公司地址" />
      </div>
      <div
        @click="jumptodetail(item.roomId, item)"
        v-for="item in houselist"
        :key="item.index"
        class="house1"
      >
        <img :src="item.image" alt="" />
        <div class="intrduce">
          <span class="title1">{{ item.subdistrict }}</span>
          <span class="title2"
            ><span>{{ item.rentalWay }}</span
            >|<span>{{ item.houseType }}</span
            >|<span>{{ item.roomAcre }}</span
            >|<span>{{ item.floor }}</span></span
          >
          <span v-show="item.distance" class="title2"
            ><van-icon name="location" />{{ item.distance }}</span
          >
          <div class="tips">
            <span>{{ item.rentalWay }}</span>
            <span>{{ item.paymentMethod }}</span>
            <span>{{ item.houseType }}</span>
          </div>
          <span class="title3">{{ item.price }}</span>
        </div>
      </div>
      <div v-if="showNo" class="nopart">
        <div>很抱歉，没有找到您搜索的地址</div>
      </div>
    </div>
    <div class="slot"></div>
    <div class="btnpart">
      <van-button @click="houseSearch">筛选房源</van-button>
      <div class="safe"></div>
    </div>
  </div>
</template>

<script>
import { getTianPeriphery, getTianPosition } from "../../apis/map.js";
import local from "../../utils/local.js";
import { _local } from "@/utils/storage";
import { vaguesearch } from "../../apis/house.js";
// import {getNearby,getLnt} from "@/apis/city"

export default {
  data() {
    return {
      time: 10,
      distance: 5,
      address: "",
      data: [],
      showNo: false,
      lng: "",
      lat: "",
      houselist: [],
      currentPage: 1,
    };
  },
  watch: {
    address(newValue, oldValue) {
      if (newValue) {
        this.houselist = [];
        this.currentPage = 1;
      }
    },
  },
  beforeUpdate() {
    window.addEventListener("scroll", this.showScroll);
  },
  beforeDestroy() {
    window.removeEventListener("scroll", this.showScroll);
  },
  methods: {
    showScroll() {
      const _this = this;
      let scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      let windowHeight =
        document.documentElement.clientHeight || document.body.clientHeight;
      let scrollHeight =
        document.documentElement.scrollHeight || document.body.scrollHeight;
      if (scrollTop + windowHeight >= scrollHeight - 20) {
        _this.currentPage++;
        _this.houseSearch();
      }
    },
    jumptodetail(e, item) {
      this.$router.push({ path: "/housedetail", query: { roomId: e } });
    },
    houseSearch() {
      if (this.address.trim() != "") {
        this.$toast.loading({
          duration: 0,
          message: "加载中...",
          forbidClick: true,
        });
        vaguesearch({
          content: this.address,
          currentPage: this.currentPage,
          perPage: 10,
          cityCode: _local.get("cityCode"),
        }).then((res) => {
          console.log(res);
          if (res.code == 200 || res.code == 201) {
            this.$toast.clear();
            this.showNo = false;
            this.houselist = this.houselist.concat(res.result.list);
          } else {
            this.showNo = true;
          }
        });
      } else {
        this.$toast("请输入地址");
      }
    },
    goback() {
      this.$router.go(-1);
    },
  },
};
</script>

<style scoped lang="less">
.slot {
  height: 50px;
}
.house1 {
  display: flex;
  margin: 10px 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f1f1;
  img {
    width: 32vw;
    height: 29.3vw;
  }
  .intrduce {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-left: 10px;
    .title1 {
      font-size: 16px;
      font-weight: 550;
      color: #333333;
      max-width: 42.6vw;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .title2 {
      font-size: 12px;
      color: #a0a0a0;
      max-width: 42.6vw;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      span {
        margin: 0 2px;
      }
    }
    .tips {
      span {
        font-size: 10px;
        display: inline-block;
        margin-right: 5px;
        padding: 2px;
        background-color: #ebfafd;
        color: #4daac1;
      }
    }
    .title3 {
      color: #d43b33;
      font-size: 16px;
      font-weight: bold;
      span {
        font-size: 12px;
        margin-left: 3px;
      }
    }
  }
}
.all {
  flex: 1;
}
.header {
  position: fixed;
  z-index: 1000;
  padding: 15px;
}
.space {
  height: 380px;
  background: url("../../assets/commutebg.png") no-repeat 0px 0px;
  background-size: 100% 100%;
}
.middlebox {
  margin: 15px;
  .intpart {
    position: relative;
    .search {
      position: absolute;
      left: 13px;
      bottom: 12px;
    }
    input {
      width: 100%;
      height: 50px;
      border: 1px solid #f1f1f1;
      border-radius: 25px;
      padding-left: 40px;
      box-sizing: border-box;
      color: #333;
    }
  }
  .adresspart {
    padding-bottom: 80px;
    > div {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #f1f1f1;
      padding-bottom: 10px;
      margin-top: 10px;
      font-size: 14px;
      color: #333;
      > button {
        width: 90px;
        background-color: #45b7cb;
        color: #fff;
        border: 1px solid #45b7cb;
        display: inline-block;
        padding: 8px 15px;
        border-radius: 20px;
      }
      > div {
        width: 200px;
        div {
          width: 200px;
          &:first-child {
            font-size: 16px;
            font-weight: bold;
            overflow: hidden;
          }
        }
      }
    }
  }
  .nopart {
    text-align: center;
    margin: 10px 0;
    color: #333;
  }
  .choosepart {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    .tipsword {
      width: 120px;
    }
    van-slider {
      padding: 0 20px;
      flex: 1;
    }
  }
}
.btnpart {
  position: fixed;
  bottom: 0px;
  width: 100%;
  text-align: center;
  background-color: #fff;
  padding: 10px 0;
  z-index: 2000;
  .van-button {
    display: inline-block;
    width: 90%;
    font-size: 16px;
    color: #fff;
    background-image: linear-gradient(to bottom right, #6fccdd, #49b9cd);
    border-radius: 20px;
    border: none;
  }
  .safe {
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
  }
}
</style>
